package com.ddh.bankmanager.controller;

import com.ddh.bankmanager.annotation.AuthCheck;
import com.ddh.bankmanager.common.BaseEntity;
import com.ddh.bankmanager.common.Result;
import com.ddh.bankmanager.constant.UserConstant;
import com.ddh.bankmanager.domain.customerinfo.CustomerInfo;
import com.ddh.bankmanager.domain.customerinfo.dto.CustomerInfoLoginDTO;
import com.ddh.bankmanager.domain.customerinfo.dto.CustomerInfoQueryDTO;
import com.ddh.bankmanager.domain.customerinfo.dto.CustomerInfoRegisterDTO;
import com.ddh.bankmanager.domain.customerinfo.vo.CustomerInfoVO;
import com.ddh.bankmanager.enum_.RoleEnum;
import com.ddh.bankmanager.service.CustomerInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/customerInfo")
@Api(tags = "客户信息")
public class CustomerInfoController {

    @Resource
    private CustomerInfoService customerInfoService;

    @ApiOperation("登录")
    @PostMapping("/login")
    public Result<CustomerInfoVO> login(@RequestBody CustomerInfoLoginDTO customerInfoLoginDTO){
        CustomerInfoVO customerInfoVO = customerInfoService.login(customerInfoLoginDTO);
        return Result.success(customerInfoVO);
    }

    @ApiOperation("注册")
    @PostMapping("/register")
    public Result<Boolean> register(@RequestBody CustomerInfoRegisterDTO customerInfoRegisterDTO){
        Boolean register = customerInfoService.register(customerInfoRegisterDTO);
        return Result.success(register);
    }

    @PostMapping("/getCustomerInfoList")
    @ApiOperation("获取客户信息列表")
    @AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
    public Result<BaseEntity<CustomerInfo>> getCustomerInfoList(@RequestBody CustomerInfoQueryDTO customerInfoQueryDTO){
        BaseEntity<CustomerInfo> baseEntity = customerInfoService.getCustomerInfoList(customerInfoQueryDTO);
        return Result.success(baseEntity);
    }

    @GetMapping("/current")
    @ApiOperation("获取当前登录用户信息")
    public Result<CustomerInfo> current(){
        CustomerInfo current = customerInfoService.current();
        return Result.success(current);
    }
}
